package com.fyh.entity.common;

import lombok.Data;

@Data
public class Result<T> {

    public static final String SUCCESS_CODE = "200";
    public static final String ERROR_CODE = "500";

    private String code;
    private String msg;
    private T data;

    public Result(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public Result() {
    }
    public static <T> Result<T> success() {
        return new Result<>(SUCCESS_CODE, "success", null);
    }
    public static <T> Result<T> success(T data) {
        return new Result<>(SUCCESS_CODE, "success", data);
    }
    public static <T> Result<T> success(String msg, T data) {
        return new Result<>(ERROR_CODE, msg, data);
    }
    public static <T> Result<T> error(String code, String msg) {
        return new Result<>(code, msg, null);
    }
    public static <T> Result<T> error(String msg) {
        return new Result<>(ERROR_CODE, msg, null);
    }
}
